package com.qf.bbapi.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.bbapi.config.SystemConfig;
import com.qf.bbapi.dto.ShopCarInfoDto;
import com.qf.bbapi.entity.ShopCar;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author wodexinhuai
 * @create 2022-07-02-17:58
 */
public interface ShopCarDao extends BaseMapper<ShopCar> {
    /**
     * 商品数量+1
     */
    @Update("update t_shop_car set goods_num = (goods_num + 1) where uid = #{token} and goods_id = #{goodsId}")
    int addOne(@Param(SystemConfig.TOKEN_HEADER) int uid, @Param("goods_id") long goodsId);

    /**
     * 商品数量+1
     */
    @Update("update t_shop_car set goods_num = (goods_num - 1) where uid = #{token} and goods_id = #{goodsId}")
    int minusOne(@Param(SystemConfig.TOKEN_HEADER) int uid, @Param("goods_id") long goodsId);

    /**
     * 查询某用户的所有购物车信息 包含总价
     */
    List<ShopCarInfoDto> shopCarInfo(@Param(SystemConfig.TOKEN_HEADER) int uid);


    /**
     * 展示部分用户选中的
     *
     * @return
     */
    List<ShopCarInfoDto> shopPart(List<Long> ids);

    @Update("update t_shop_car set goods_num = #{goodsNum} where  id = #{id}")
    int updateGoodsNum(Long id ,Integer goodsNum);

}
